package com.five.twentyfouth;

/*
需求:设计一个方法用于获取数组中元素的最大值
 */
public class Test015 {
    public static void main(String[] args) {
        int[]arr={10,20,30,40,50,60,70,80,90};
        int max = getMax(arr);
        int min = getMin(arr);
        int[]arr1={90,80,70,60,50,40,30,20,10};
        int max1 = getMax(arr1);
        int min1 = getMin(arr1);
        System.out.println("arr最大值是" + max);
        System.out.println("arr最小值是" + min);
        System.out.println("arr1最大值是" + max1);
        System.out.println("arr1最小值是" + min1);

    }

    public static int getMax(int[] arr) {
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            //  arr[i]
            if (max < arr[i]) {
                max = arr[i];

            }
        }
        return max;

    }
    public static int getMin(int[]arr){
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            // arr[i]
            if (min>arr[i]){
                min =arr[i];
            }
        }return min;
    }
}

